home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 3 of 3.iso / chapte19 / pause.c < prev    next >
C/C++ Source or Header  |  1996-04-29  |  7KB  |  244 lines

  1.  
  2. #include <windows.h>
  3. #include <stdio.h>
  4. #include "Pause.h"
  5. #include <vfw.h>
  6.  
  7. #if defined (WIN32)
  8.     #define IS_WIN32 TRUE
  9. #else
  10.     #define IS_WIN32 FALSE
  11. #endif
  12.  
  13. #define IS_NT      IS_WIN32 && (BOOL)(GetVersion() < 0x80000000)
  14. #define IS_WIN32S  IS_WIN32 && (BOOL)(!(IS_NT) && (LOBYTE(LOWORD(GetVersion()))<4))
  15. #define IS_WIN95   (BOOL)(!(IS_NT) && !(IS_WIN32S)) && IS_WIN32
  16.  
  17.  
  18. HINSTANCE hInst;   // current instance
  19.  
  20. LPCTSTR lpszAppName = "MyApp";
  21. LPCTSTR lpszTitle   = "My Application"; 
  22.  
  23. // the rest of the stuff
  24. //......................
  25.  
  26. BOOL RegisterWin95( CONST WNDCLASS* lpwc );
  27.  
  28.  
  29. int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  30.                       LPTSTR lpCmdLine, int nCmdShow)
  31. {
  32.    MSG      msg;
  33.    HWND     hWnd; 
  34.    WNDCLASS wc;
  35.  
  36.    wc.style         = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  37.    wc.lpfnWndProc   = (WNDPROC)WndProc;       
  38.    wc.cbClsExtra    = 0;                      
  39.    wc.cbWndExtra    = 0;                      
  40.    wc.hInstance     = hInstance;              
  41.    wc.hIcon         = LoadIcon (hInstance, lpszAppName); 
  42.    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  43.    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  44.    wc.lpszMenuName  = lpszAppName;              
  45.    wc.lpszClassName = lpszAppName;              
  46.  
  47.    if ( IS_WIN95 )
  48.    {
  49.       if ( !RegisterWin95( &wc ) )
  50.          return( FALSE );
  51.    }
  52.    else if ( !RegisterClass( &wc ) )
  53.       return( FALSE );
  54.  
  55.    hInst = hInstance; 
  56.  
  57.    hWnd = CreateWindow( lpszAppName, 
  58.                         lpszTitle,    
  59.                         WS_OVERLAPPEDWINDOW, 
  60.                         CW_USEDEFAULT, 0, 
  61.                         CW_USEDEFAULT, 0,  
  62.                         NULL,              
  63.                         NULL,              
  64.                         hInstance,         
  65.                         NULL               
  66.                       );
  67.  
  68.    if ( !hWnd ) 
  69.       return( FALSE );
  70.  
  71.    ShowWindow( hWnd, nCmdShow ); 
  72.    UpdateWindow( hWnd );         
  73.  
  74.    while( GetMessage( &msg, NULL, 0, 0) )   
  75.    {
  76.       TranslateMessage( &msg ); 
  77.       DispatchMessage( &msg );  
  78.    }
  79.  
  80.    return( msg.wParam ); 
  81. }
  82.  
  83.  
  84. BOOL RegisterWin95( CONST WNDCLASS* lpwc )
  85. {
  86.     WNDCLASSEX wcex;
  87.  
  88.    wcex.style         = lpwc->style;
  89.    wcex.lpfnWndProc   = lpwc->lpfnWndProc;
  90.    wcex.cbClsExtra    = lpwc->cbClsExtra;
  91.    wcex.cbWndExtra    = lpwc->cbWndExtra;
  92.    wcex.hInstance     = lpwc->hInstance;
  93.    wcex.hIcon         = lpwc->hIcon;
  94.    wcex.hCursor       = lpwc->hCursor;
  95.    wcex.hbrBackground = lpwc->hbrBackground;
  96.    wcex.lpszMenuName  = lpwc->lpszMenuName;
  97.    wcex.lpszClassName = lpwc->lpszClassName;
  98.  
  99.    // Added elements for Windows 95.
  100.    //...............................
  101.    wcex.cbSize = sizeof(WNDCLASSEX);
  102.    wcex.hIconSm = LoadImage(wcex.hInstance, lpwc->lpszClassName, 
  103.                             IMAGE_ICON, 16, 16,
  104.                             LR_DEFAULTCOLOR );
  105.             
  106.    return RegisterClassEx( &wcex );
  107. }
  108.  
  109. HWND hMCIWnd = NULL;   // MCIWnd window handle
  110.  
  111. LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  112. {
  113.    switch( uMsg )
  114.    {
  115.       case WM_CREATE :
  116.               // create MCIWnd window
  117.               //.....................
  118.  
  119.               hMCIWnd = MCIWndCreate(hWnd, hInst, 
  120.                                      WS_VISIBLE | 
  121.                                      WS_CHILD | 
  122.                                      WS_OVERLAPPED |
  123.                                      WS_CAPTION |
  124.                                      WS_BORDER |
  125.                                      MCIWNDF_NOTIFYMODE |
  126.                                      MCIWNDF_SHOWALL | 
  127.                                      MCIWNDF_NOPLAYBAR, 
  128.                                      NULL
  129.                                     );
  130.                           
  131.               if (!hMCIWnd)
  132.               {
  133.                   MessageBox(hWnd, "Error creating MCIWnd window...", 
  134.                              NULL, MB_OK);
  135.                   DestroyWindow( hWnd );
  136.               }
  137.               break;
  138.  
  139.       case WM_COMMAND :
  140.               switch( LOWORD( wParam ) )
  141.               {
  142.                  // file commands
  143.                  //..............
  144.  
  145.                  case IDM_OPEN_DIALOG :
  146.                          if ( MCIWndOpenDialog(hMCIWnd) )
  147.                              MCIWndValidateMedia(hMCIWnd);
  148.                          break;
  149.                          
  150.                  case IDM_CLOSE :
  151.                          MCIWndClose(hMCIWnd);
  152.                          break;
  153.  
  154.                  // playback
  155.                  //.........
  156.                                            
  157.                  case IDM_PLAY :
  158.                          MCIWndPlay(hMCIWnd);
  159.                          break;
  160.                                    
  161.                  case IDM_PAUSE :
  162.                          MCIWndPause(hMCIWnd);
  163.                          break;
  164.                  
  165.                  case IDM_RESUME : 
  166.                          MCIWndResume(hMCIWnd);
  167.                          break;
  168.                  
  169.                  case IDM_STOP :
  170.                          MCIWndStop(hMCIWnd);
  171.                          break;
  172.                                            
  173.                  case IDM_STEP_FORWARD :
  174.                          MCIWndStep(hMCIWnd, 1);
  175.                          break;
  176.                  
  177.                  case IDM_STEP_BACKWARD :
  178.                          MCIWndStep(hMCIWnd, -1); 
  179.                          break;
  180.  
  181.                  // other commands
  182.                  //...............
  183.                  
  184.                  case IDM_ABOUT :
  185.                         DialogBox( hInst, "AboutBox", hWnd, (DLGPROC)About );
  186.                         break;
  187.  
  188.                  case IDM_EXIT :
  189.                         DestroyWindow(hWnd);
  190.                         break;
  191.               }
  192.               break;
  193.  
  194.       case WM_DESTROY :
  195.               // destroy MCIWnd, if one exists
  196.               //..............................
  197.  
  198.               if (hMCIWnd)
  199.                   MCIWndDestroy(hMCIWnd);
  200.  
  201.               PostQuitMessage(0);
  202.               break;
  203.  
  204.       default :
  205.             return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
  206.    }
  207.  
  208.    return( 0L );               
  209. }
  210.  
  211.  
  212. LRESULT CALLBACK About( HWND hDlg,           
  213.                         UINT message,        
  214.                         WPARAM wParam,       
  215.                         LPARAM lParam)
  216. {
  217.    switch (message) 
  218.    {
  219.        case WM_INITDIALOG: 
  220.                return (TRUE);
  221.  
  222.        case WM_COMMAND:                              
  223.                if (   LOWORD(wParam) == IDOK         
  224.                    || LOWORD(wParam) == IDCANCEL)    
  225.                {
  226.                        EndDialog(hDlg, TRUE);        
  227.                        return (TRUE);
  228.                }
  229.                break;
  230.    }
  231.  
  232.    return (FALSE); 
  233. }
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.